package com.wbl.train.business.mq.consumer;

import com.alibaba.fastjson2.JSON;
import com.wbl.train.business.service.ConfirmOrderService;
import com.wbl.train.common.business.dto.ConfirmOrderDto;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

/**
 * Author: 王博纶
 * Date: 2024/5/27 15:08
 * FileName: ConfirmOrderConsumer
 * Description: 确认订单出票的消费类
 */
@Slf4j
@RocketMQMessageListener(consumerGroup = "default",topic = "CONFIRM_ORDER")
@Service
public class ConfirmOrderConsumer implements RocketMQListener<MessageExt> {

    @Resource
    private ConfirmOrderService confirmOrderService;

    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        log.info("ROCKETMQ收到消息：{}",new String(body));
        // 将json转换为对象
        ConfirmOrderDto jsonObject = JSON.parseObject(new String(body),ConfirmOrderDto.class);
        // 调用出单的方法的逻辑
        boolean b = confirmOrderService.doConfirm(jsonObject);
    }
}
